package com.jcj.jcjrpc.core.cluster;

import com.jcj.jcjrpc.core.api.LoadBalancer;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Random;

public class RandomLoadBalancer<T> implements LoadBalancer<T> {
    Random random = new Random();

    @Override
    public T choose(List<T> providers) {
        if (CollectionUtils.isEmpty(providers)) {
            return null;
        }
        return providers.get(random.nextInt(providers.size()));
    }
}
